﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AccessUI.aspx.cs" Inherits="CSharp.Admin.AccessUI" MasterPageFile="~/Admin/Admin.Master" EnableEventValidation="true" %>
<%@ Register Src="~/UserControl/MsgUC.ascx" TagName="MsgUC" TagPrefix="uc1" %>
<asp:Content ID="cBody" runat="server" ContentPlaceHolderID="cphBody">
   
    <uc1:msguc id="MsgUC1" runat="server" />
    <asp:PlaceHolder ID="phMain" runat="server"></asp:PlaceHolder>
    <asp:Panel ID="Panel1" runat="server" Visible="false">
     <%--<asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick"></asp:Timer>--%>
    <br />
    <asp:TextBox ID="txtInput" runat="server" Width="800px"></asp:TextBox>
    <br />
    <asp:Button ID="btnGetID" runat="server" Text="GetID" onclick="btnGetID_Click" />
    <asp:Label ID="lblGetID" runat="server"></asp:Label>
    <div class="container">
        <div class="table-responsive">
            <table id="divThangNM" class="lstDoubleTableInput table table-striped table-bordered table-hover dataTable no-footer styleGrid">
                <tr>
                    <th style="width: 20%;">
                        Tên thuộc tính
                    </th>
                    <th>
                        Giá trị
                    </th>
                    <th style="width: 42px; padding: 5px !important;">
                    </th>
                </tr>
                <!--tr will be added here -->
            </table>
            <input class="divThangNM_DataTextBox1" type="hidden" value='<%=divThangNM_DataTextBox1%>' />
            <input class="divThangNM_DataTextBox2" type="hidden" value='<%=divThangNM_DataTextBox2%>' />
            <input id="divThangNM_btnAddNewItem" type="button" value="Thêm thuộc tính" onclick="func_DoubleTextBox_AddNewItem(divThangNM)" />
        </div>
        <br />
        <br />
        <div class="table-responsive">
            <table id="divDuongNTH" class="lstDoubleTableInput table table-striped table-bordered table-hover dataTable no-footer styleGrid">
                <tr>
                    <th style="width: 20%;">
                        Tên thuộc tính
                    </th>
                    <th>
                        Giá trị
                    </th>
                    <th style="width: 42px; padding: 5px !important;">
                    </th>
                </tr>
                <!--tr will be added here -->
            </table>
            <input class="divDuongNTH_DataTextBox1" type="hidden" value='<%=divDuongNTH_DataTextBox1%>' />
            <input class="divDuongNTH_DataTextBox2" type="hidden" value='<%=divDuongNTH_DataTextBox2%>' />
            <input id="divDuongNTH_btnAddNewItem" type="button" value="Thêm thuộc tính" onclick="func_DoubleTextBox_AddNewItem(divDuongNTH)" />
        </div>
        <br />
        <br />
        <asp:Button ID="btnGet" runat="server" Text="Get" OnClick="btnGet_Click" /><br />
        <br />
        <br />
        <br />
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">
                    Panel title</h3>
            </div>
            <div class="panel-body table-responsive">
                <table id="divABC" class="lstSingleTableInput table table-striped table-bordered table-hover dataTable no-footer styleGrid">
                    <tr>
                        <th>
                            Giá trị
                        </th>
                        <th style="width: 42px; padding: 5px !important;">
                        </th>
                    </tr>
                    <!--tr will be added here -->
                </table>
            </div>
            <div class="panel-footer">
                <input class="divABC_DataTextBox0" type="hidden" value='<%=divABC_DataTextBox0%>' />
                <input id="divABC_btnAddNewItem" type="button" value="Thêm thuộc tính" onclick="func_SingleTextBox_AddNewItem(divABC)" />
            </div>
        </div>
        <%--<div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">
                    Panel title</h3>
            </div>
            <div class="panel-body">
                <input class="divContainerTextBox2_Value" type="hidden" value='<%=divContainerTextBox2%>' />
                <div id="divContainerTextBox2" class="lstTextBox">
                    <!--Textboxes will be added here -->
                </div>
            </div>
            <div class="panel-footer">
                <input id="btnAdd2" type="button" value="add2" onclick="func_SingleTextBox_AddNewItem(divContainerTextBox2)" /><br />
            </div>
        </div>--%>
        <br />
        <asp:Button ID="btnPost" runat="server" Text="Post" OnClick="btnPost_Click" CssClass="btn btn-danger" />
    </div>
    </asp:Panel>
    <script type="text/javascript">
        function func_DoubleTextBox_GetHtmlCodeItem(idInput, valDefault1, valDefault2) {
            return '<td style="padding:5px !important;"><input name="' + idInput + '_ValueTextBox1" type="text" value="' + valDefault1 + '"  class="form-control" autocomplete="off" required /></td>' +
            '<td style="padding:5px !important;"><input name="' + idInput + '_ValueTextBox2" type="text" value="' + valDefault2 + '"  class="form-control" autocomplete="off" required /></td>' +
            '<td style="width:42px; padding:5px !important;"><a class="btn btn-default" type="button" onclick="$(this).closest(\'tr\').remove();"><i class="fa fa-remove font_20"></i></a></td>';
        }
        function func_DoubleTextBox_AddNewItem(idDivCon) {
            var tagTR = document.createElement('tr');
            tagTR.innerHTML = func_DoubleTextBox_GetHtmlCodeItem(idDivCon.id, "", "");
            idDivCon.appendChild(tagTR);
        }
        function func_DoubleTextBox_ReBuild() {
            var lstTableInput = new Array();
            lstTableInput = document.getElementsByClassName("lstDoubleTableInput");
            for (var i = 0; i < lstTableInput.length; i++) {
                var arrDataTextBox1 = eval(func_Decrypt(document.getElementsByClassName(lstTableInput[i].id + "_DataTextBox1")[0].value));
                var arrDataTextBox2 = eval(func_Decrypt(document.getElementsByClassName(lstTableInput[i].id + "_DataTextBox2")[0].value));
                if (arrDataTextBox1 != null) {
                    var html = "<tr><th style=\"width: 20%;\">Tên thuộc tính</th><th>Giá trị</th><th style=\"width: 42px; padding: 5px !important;\"></th></tr>";
                    for (var j = 0; j < arrDataTextBox1.length; j++) {
                        html += "<tr>" + func_DoubleTextBox_GetHtmlCodeItem(lstTableInput[i].id, arrDataTextBox1[j], arrDataTextBox2[j]) + "</tr>";
                    }
                    lstTableInput[i].innerHTML = html;
                }
            }
        }



        function func_SingleTextBox_GetHtmlCodeItem(idInput, valDefault) {
            return '<td style="padding:5px !important;"><input name="' + idInput + '_ValueTextBox0" type="text" value="' + valDefault + '"  class="form-control" autocomplete="off" required /></td>' +
            '<td style="width:42px; padding:5px !important;"><a class="btn btn-default" type="button" onclick="$(this).closest(\'tr\').remove();"><i class="fa fa-remove font_20"></i></a></td>';
        }
        function func_SingleTextBox_AddNewItem(idDivCon) {
            var tagTR = document.createElement('tr');
            tagTR.innerHTML = func_SingleTextBox_GetHtmlCodeItem(idDivCon.id, "");
            idDivCon.appendChild(tagTR);
        }
        function func_SingleTextBox_ReBuild() {
            var lstTableInput = new Array();
            lstTableInput = document.getElementsByClassName("lstSingleTableInput");
            for (var i = 0; i < lstTableInput.length; i++) {
                var values = eval(func_Decrypt(document.getElementsByClassName(lstTableInput[i].id + "_DataTextBox0")[0].value));
                if (values != null) {
                    var html = "<tr><th>Giá trị</th><th style=\"width: 42px; padding: 5px !important;\"></th></tr>";
                    for (var j = 0; j < values.length; j++) {
                        html += "<tr>" + func_SingleTextBox_GetHtmlCodeItem(lstTableInput[i].id, values[j]) + "</tr>";
                    }
                    lstTableInput[i].innerHTML = html;
                }
            }
        }

        function func_LoadAllConfigDynamicTextBox() {
            func_SingleTextBox_ReBuild();
            func_DoubleTextBox_ReBuild();
        }

        function func_Decrypt(strInput) {
            //return btoa(strInput);
            //return atob(strInput);

            //return window.btoa(unescape(encodeURIComponent(strInput)));

            //strInput = strInput.replace(/\s/g, '');    
            return decodeURIComponent(escape(window.atob(strInput)));
        }

        window.onload = func_LoadAllConfigDynamicTextBox();
    </script>
</asp:Content>
